<%@ page language="java"
         contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"
         import="com.shxt.hotel.background.Consume"
         import="com.shxt.hotel.background.User"
         import="java.util.List"
         import="java.util.Map"
%>
<%
    Consume consume = new Consume();
    User user = new User();
    
    Map<String, Object> currentUser;
    
    if(session.getAttribute("id") == null){
        response.sendRedirect("./login.jsp");
    }else{
        currentUser = user.getUserInfo((int)session.getAttribute("id"));
%>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Mosaddek">
    <link rel="shortcut icon" href="../Public/img/favicon.html">

    <title>Basic Table</title>

    <!-- Bootstrap core CSS -->
    <link href="../Public/css/bootstrap.min.css" rel="stylesheet">
    <link href="../Public/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="../Public/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="../Public/css/style.css" rel="stylesheet">
    <link href="../Public/css/style-responsive.css" rel="stylesheet" />

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
      <script src="../Public/js/html5shiv.js"></script>
      <script src="../Public/js/respond.min.js"></script>
    <![endif]-->
</head>

<body>

    <section id="container" class="">
        <!--header start-->
        <jsp:include page="./Public/header.jsp" flush="true" />
        <!--header end-->
        <!--sidebar start-->
        <jsp:include page="./Public/sidebar.jsp" flush="true" />
        <!--sidebar end-->
        <!--main content start-->
        <section id="main-content">
            <section class="wrapper">
                <!-- page start-->
                <div class="row">
                    <div class="col-lg-8">
                        <%
                            List<Map<String, Object>> conList = consume.getConsumes();
                            List<Map<String, Object>> cateList = consume.getCategories();
                            
                            for(Map<String, Object> cate : cateList){
                                
                        %>
                            <section class="panel panel-primary">
                                <header class="panel-heading">
                                    <%=cate.get("title") %>
                                </header>
                                <table class="table table-striped table-advance table-hover">
                                    <thead>
                                        <tr>
                                            <th><i class="icon-bullhorn"></i> ID</th>
                                            <th class="hidden-phone"><i class="icon-question-sign"></i> Cosnume Name</th>
                                            <th><i class="icon-bookmark"></i> Category</th>
                                            <th><i class=" icon-edit"></i> Price</th>
                                            <th>Operation</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <%
                                            int pid = (int)currentUser.get("user_permission");
                                            Map<String, Object> userPerm = user.getPermission(pid);
                                        
                                            for(Map<String, Object> con : conList){
                                                if((int)con.get("category") == (int)cate.get("id")){
                                        %>
                                        <tr id='hotel_consume_id_<%=con.get("id") %>'>
                                            <td form-data="id">
                                                <a href="../Public/#">
                                                    <span class="consume_content"><%=con.get("id") %></span>
                                                </a>
                                            </td>
                                            <td class="hidden-phone" form-data="title">
                                                <span class="consume_content"><%=con.get("title") %></span>
                                            </td>
                                            <td>
                                                <span class="consume_content"><%=cate.get("title") %></span>
                                            </td>
                                            <td form-data="price">
                                                $ <span class="consume_content"><%=con.get("price") %> &nbsp;</span>
                                                <%
                                                    if((int)userPerm.get("id") != 0){
                                                %>
                                                    <span class="label label-danger">-&nbsp;<%=userPerm.get("consume_discount") %>%</span>
                                                <%
                                                    }
                                                %>
                                            </td>
                                            <td>
                                                <button class="btn btn-info btn-xs" onclick='addToCart(<%=con.get("id") %>)'>Add to cart</button>
                                            </td>
                                        </tr>
                                        <%
                                                }
                                            }
                                        %>
                                    </tbody>
                                </table>
                            </section>
                        <%
                            }
                        %>
                    </div>
                    <div class="col-lg-4">
                        <section class="panel panel-danger affix">
                            <header class="panel-heading ">
                                Shopping Cart
                            </header>
                            <table class="table table-striped" id="hotel_consume_shopping_cart">
                                <thead>
                                    <tr>
                                        <th>Name</th>
                                        <th>Price</th>
                                        <th>Num</th>
                                        <th>Oprt</th>
                                    </tr>
                                </thead>
                                <tbody id="hotel_consume_shopping_cart_tbody">
                                    
                                </tbody>
                            </table>
                            <footer class="twt-footer">
                                <button class="btn btn-white" data-toggle="button">
                                    Total Cost: &nbsp; $<span id="hotel_consume_shopping_cart_total_cost" class="text-danger"> 0</span>
                                </button>
                                <button type="button" class="btn btn-info pull-right" onclick="submitCart()">Submit</button>
                            </footer>
                            </div>
                        </section>
                    </div>
                </div>
                <!-- page end-->
            </section>
        </section>
        <!--main content end-->
    </section>

    <!-- js placed at the end of the document so the pages load faster -->
    <script src="../Public/js/jquery.js"></script>
    <script src="../Public/js/bootstrap.min.js"></script>
    <script src="../Public/js/jquery.scrollTo.min.js"></script>
    <script src="../Public/js/jquery.nicescroll.js" type="text/javascript"></script>


    <!--common script for all pages-->
    <script src="../Public/js/common-scripts.js"></script>
    
    <!-- script by myself -->
    <script src='../Public/Cus/js/hotel_consume.js'></script>
    
    <script>
        $(document).ready(function(){
            $("#Hotel_Service").addClass("active");
            $("#hotel_consume").addClass("active");
        });
    </script>


</body>

</html>
<%
    }
%>